
#pragma once

#include "cybertron/DefinesCore.hpp"
#include "cybertron/core/StackArray.hpp"
#include <memory>
#include <mutex>
#include <vector>

CYBERTRON_BEGIN

class SocketEventHandlerList : public std::enable_shared_from_this<SocketEventHandlerList>
{
public:
	SocketEventHandlerList();
	~SocketEventHandlerList();

	void addHandler(SocketEventHandlerPtr pHandler);
	void removeHandler(SocketEventHandlerPtr pHandler);

	bool onMessage(Message& msg);
	bool onConnected();
	bool onDisconnected();

private:
	SocketEventHandlerList(const SocketEventHandlerList&);
	SocketEventHandlerList(SocketEventHandlerList&&);
	SocketEventHandlerList& operator = (const SocketEventHandlerList&);
	SocketEventHandlerList& operator = (SocketEventHandlerList&&);

private:
#if defined(DEBUG) || defined(_DEBUG)
	typedef std::vector<SocketEventHandlerPtr> HandlerArray;
#else
	typedef StackArray<SocketEventHandlerPtr, 8> HandlerArray;
#endif

	std::recursive_mutex mEventHandlerMutex;
	HandlerArray mEventHandlers;
};

CYBERTRON_END
